package com.itcast.demoone.kotlin


// 通过类创建一个对象, 传入车辆的类型, 最终输出车辆的类型和车轮的数量
class Vehicle(var types: String) {
    var wheelNum: Int = 0

    init {
        when (types) {
            "自行车" -> wheelNum = 2
            "轿车" -> wheelNum = 4
            "大货车" -> wheelNum = 8
            "小货车" -> wheelNum = 6
            else -> println("没有此车辆")
        }
    }

    constructor(types: String, wheelNum: Int) : this(types) {
        this.wheelNum = wheelNum
    }

    fun show() {
        println("$types 车轮的数量: $wheelNum")
    }
}

fun main() {
    val car1 = Vehicle("小货车")
    car1.show()

    val car2 = Vehicle("自行车", 13)
    car2.show()
}